22 template <class T
> string
toStr(const T
&x
){ stringstream s
; s
<< x
; return s
.str(); }
23 template <class T
> int toInt(const T
&x
){ stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
25 #define For(i, a, b) for (int i=(a); i<(b); ++i)
26 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
27 #define D(x) cout << #x " = " << (x) << endl
29 #define assign(x, y) memcpy(x, y, sizeof(y))
31 const int MOD
= 1000000007;
37 int odd
[MAXN
][MAXN
], even
[MAXN
][MAXN
], T
[MAXN
][MAXN
], C
[MAXN
][MAXN
], ans
[1][MAXN
];
39 void mul(int A
[MAXN
][MAXN
], int B
[MAXN
][MAXN
], int C
[MAXN
][MAXN
], int p
, int q
, int r
){
40 for (int i
=0; i
<p
; ++i
){
41 for (int j
=0; j
<r
; ++j
){
43 for (int k
=0; k
<q
; ++k
){
44 C
[i
][j
] += A
[i
][k
] * B
[k
][j
];
53 void exp(int A
[MAXN
][MAXN
], int C
[MAXN
][MAXN
], int n
, int e
){
56 for (int i
=0; i
<n
; ++i
){
57 for (int j
=0; j
<n
; ++j
){
72 mul(C
, C
, TT
, n
, n
, n
);
75 mul(C
, A
, TT
, n
, n
, n
);
84 for (int Caso
=1; Caso
<=Casos
; ++Caso
){
86 if (!(cin
>> n
>> m
>> k
>> d
)) break;
87 for (int i
=0; i
<n
; ++i
){
93 int u
, v
; cin
>> u
>> v
;
94 g
[u
].push_back(v
), g
[v
].push_back(u
);
97 //find day of sum for each node
102 int u
= q
.front(); q
.pop();
112 //find odd/even matrices
113 for (int j
=0; j
<n
; ++j
){
114 for (int i
=0; i
<n
; ++i
){
115 odd
[i
][j
] = even
[i
][j
] = 0;
125 even
[j
][j
] = odd
[j
][j
] = 1;
128 //D("odd"); For(i, 0, n){ For(j, 0, n) printf("%d ", odd[i][j]); printf("\n"); }
130 //D("even"); For(i, 0, n){ For(j, 0, n) printf("%d ", even[i][j]); printf("\n"); }
134 mul(odd
, even
, C
, n
, n
, n
);
139 mul(C
, odd
, T
, n
, n
, n
);
143 D("C"); For(i
, 0, n
){ For(j
, 0, n
) printf("%d ", C
[i
][j
]); printf("\n"); }
145 for (int j
=0; j
<n
; ++j
){
150 mul(ans
, C
, T
, 1, n
, n
);
152 printf("Case %d:", Caso
);
153 for (int j
=0; j
<n
; ++j
){
154 printf(" %d", T
[0][j
]);